<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    const obj = {}
    Object.defineProperty(obj, 'name', {
      //对对象的属性访问进行拦截，返回的值就是外部此次访问得到的值
      get() {
        console.log('get触发了');
        return name;
      },
      //对对象的属性进行修改，set唯一接受的参数就是外部将要修改的属性的值
      set(n) {
        console.log('set触发了');
        // name = n
      }
    })
    obj.name = '白粉花';
    console.log(obj.name);
  </script>
</body>

</html>